using System;
using ShawnFramework;
using Unity.VisualScripting;
using UnityEngine;

public class Bullet : MonoBehaviour
{
    [Header("飞行速度")] 
    public float flySpeed = 8f;
    
    private Vector3 _dir;

    private void Update()
    {
        if (_dir == Vector3.zero)
            return;
        
        // 飞行
        Vector3 curPos = transform.position;
        Vector3 targetPos = curPos + _dir * (flySpeed * Time.deltaTime);
        transform.position = Vector3.MoveTowards(curPos, targetPos, flySpeed * Time.deltaTime);
    }

    public void ApplyFlyParams(Vector3 dir)
    {
        _dir = dir;
    }

    private void OnCollisionEnter(Collision other)
    {
        if (other.transform.CompareTag("Enemy"))
        {
            // 销毁敌方
            ObjectPool.Global.Recycle(PoolElemTypeEnum.Enemy00, other.gameObject);
        }
    }
}
